package com.linkage.educloud.ah.view.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.adapter.PersonParentAdapter;
import com.linkage.educloud.ah.adapter.PersonTeacherAdapter;
import com.linkage.educloud.ah.bean.AccountData;
import com.linkage.educloud.ah.bean.PersonInfo;
import com.linkage.educloud.ah.config.AccountConfig;
import com.linkage.educloud.ah.mvp.contract.mine.IPersonInfoContract;
import com.linkage.educloud.ah.mvp.presenter.mine.PersonInfoPresenter;
import com.linkage.educloud.ah.util.ImageLoader;
import com.linkage.educloud.ah.view.BasicTitleActivity;
import com.linkage.educloud.ah.widget.MyMore;
import com.linkage.educloud.ah.widget.NoScrollListView;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Mr'Tang on 2018/12/13.
 */

public class PersonInfoActivity extends BasicTitleActivity implements IPersonInfoContract.IView {

    @BindView(R.id.ac_personinfo_avater)
    CircleImageView ac_personinfo_avater;
    @BindView(R.id.ac_personinfo_name)
    MyMore ac_personinfo_name;
    @BindView(R.id.ac_personinfo_tel)
    MyMore ac_personinfo_tel;
    @BindView(R.id.ac_personinfo_grade)
    MyMore ac_personinfo_grade;
    @BindView(R.id.ac_personinfo_gradelist)
    NoScrollListView ac_personinfo_gradelist;

    AccountData accountData;
    IPersonInfoContract.IPresenter iPresenter;

    public static void launch(Context context) {
        Intent intent = new Intent(context, PersonInfoActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_personinfo;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        iPresenter = new PersonInfoPresenter(this, this);
        setTitle("个人设置");
        accountData = AccountConfig.getLoginAccount();
        ImageLoader.loadAvatar(this, accountData.getAvatar(), ac_personinfo_avater);
        ac_personinfo_name.setRightText(accountData.getUserName());
        iPresenter.getVClassSurplus(accountData.getUserType());
    }

    public void initDate(PersonInfo info) {
        ac_personinfo_tel.setRightText(info.getTel());
        if (accountData.getUserType() == 1) {
            ac_personinfo_gradelist.setAdapter(new PersonTeacherAdapter(this, info.getClasslist()));
        } else {
            ac_personinfo_gradelist.setAdapter(new PersonParentAdapter(this, info.getClasslist()));
        }
    }
}
